from langserve import RemoteRunnable
import pprint
import tkinter as tk

qa = RemoteRunnable("http://192.168.3.89:1888/rag/")

def get_chatgpt_response(user_input):
    response = qa.invoke(user_input)
    return response
  
def send_message():
    user_input = entry.get()
    chat_log.config(state=tk.NORMAL)
    chat_log.insert(tk.END, f"你: {user_input}\n")
    response = get_chatgpt_response(user_input)
    chat_log.insert(tk.END, f"ChatGPT: {response}\n")
    chat_log.config(state=tk.DISABLED)
    entry.delete(0, tk.END)
  
root = tk.Tk()
root.title("ChatGPT客户端")

chat_log = tk.Text(root, height=50, width=100, state=tk.DISABLED)
chat_log.pack()

entry = tk.Entry(root, width=80)
entry.pack()

send_button = tk.Button(root, text="发送", command=send_message)
send_button.pack()

root.mainloop()